import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { ElMessage } from 'element-plus'

import{login} from '@/apis/user'
export const useUserStore = defineStore('user', () => {
  const userInfo = ref({
  
  })

  // 登录获取用户信息
  const getUserInfo = async ({ account, password }) => {
    const res = await login({ account, password })
    if (res.code === '0') {
      userInfo.value = res.data
      ElMessage({ type: 'success', message: '登录成功' })
      return true
    } else {
      ElMessage.error(res.msg || '登录失败')
      return false
    }
  }

  return {
    userInfo,
    getUserInfo,
  }
}, {
  persist: {
    paths: ['userInfo']
  }
}) 